<!doctype html>
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">
<title>签到有礼</title>
<link href="../../css/newStyle.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../../js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../js/gbRst.js"></script>
<script type="text/javascript" src="../../js/utils.js"></script>
<script type="text/javascript" src="../../js/openId.js"></script>
<script type="text/javascript" src="../../js/ajaxfileupload.js"></script> 
<script type="text/javascript" src="../../js/header&footer.js"></script>
<!-- <script type="text/javascript" src="../../js/carService.js"></script>
 --><script type="text/javascript" src="../../js/doubleDate2.0.js"></script>
<script type="text/javascript" src="../../js/check.js"></script>
<script type="text/javascript" src="../../js/ImageBrowsing.js"></script>
<script type="text/javascript" src="../../js/qmsk-1.2.js"></script>
<script type="text/javascript" src="../../js/openId.js"></script>
<script type="text/javascript" src="../../js/communityTheme.js"></script>
<script type="text/javascript">
var imageNum =1;
var memberId = 0;
var memberName= "游客";
var imageUrl = "../../images/userImg.jpg";
$(function(){
	 winHei=$(window).height()+80;
	$(".proDetails").css("top",winHei+"px");//加载时到屏幕最下方
	$(".proDetails .placeTit").click(function(){
		$(".proDetails").animate({"top":winHei+"px"},function(){
			$("body").css("overflow-y","scroll");	
		});	
	});//点击隐藏
	
	
	
	var  member=_findInfo("../../../member/find/shopId/"+getShopId()+"/openId/"+_openId, null)
	if(IsNotEmpty(member)&&member.state==0){
		if(member.result.data.length>0){
		memberId=getHtmlString(getHeadIndexValue(0, member, "memberId"));
		var  ime=getHtmlString(getHeadIndexValue(0, member, "imageUrl"));
		if(IsNotEmpty(ime)){
			imageUrl = ime;
		}
		memberName=getHtmlString(getHeadIndexValue(0, member, "CustomerName"));
		}
	}
	
	//getCommunity()
 	getNotes(getIdByName("id"))
 	getDiscuss()
 	restForm()
	
})

function toHidden(){
	$(".proDetails").animate({"top":winHei+"px"},function(){
		$("body").css("overflow-y","scroll");	
	});	
}

function getNotes(id){
	var dt = _findInfo('../../../notes/find/note', {'shopId':_shopId,'memberId':memberId,'id':id})
	 if(dt.state==0){
		 loadNote(dt) 
	 }// 成功回调
			
}

function loadNote(dt){
	var urlThml="&openId="+getOpenId()+"&shopId = "+getShopId()
	for(var i = 0;i<dt.result.data.length;i++){
		var imgUrl = getHtmlInt(getHeadIndexValue(i, dt, "imageUrl"));
		if(IsEmpty(imgUrl)){
			imgUrl = "../../images/userImg.jpg";
		}
		var htm="<header><dl><dt><img src=\""+imgUrl+"\"></dt><dd><strong>"+getHtmlString(getHeadIndexValue(i, dt, "customerName"))+"</strong><br><time>"+getHtmlString(getHeadIndexValue(i, dt, "createdTime"))+"</time></dd></dl><aside><span>"+getHtmlString(getHeadIndexValue(i, dt, "memo"))+"</span><span class=\"red\"></span></aside></header><section>"

		var id=getHtmlString(getHeadIndexValue(i, dt, "id"))
		var imagesList= _findInfo('../../../notes/find/imageList', {'id':id})
		if(IsNotEmpty(imagesList)&&imagesList.state==0){
			var x = imagesList.result.data.length
		if(x>0){
			
		htm+="<figure data-count=\""+x+"张图片\"><div>";
		for(var j=0;j<x;j++){
		htm+="<img src=\""+getHtmlString(getHeadIndexValue(j, imagesList, "imageUrl"))+"\" data-src=\""+getHtmlString(getHeadIndexValue(j, imagesList, "imageUrl"))+"\" data-gid=\"g0\" onload=\"preViewImg(this, event);\">"
		}
		htm+="</div></figure>";
		}	

		}
		
		htm+="<h4 class=\"title abbTit\">"+getHtmlString(getHeadIndexValue(i, dt, "title"))+"</h4>"+
		"<p class='abb ' style=\"white-space:normal;\">"+replace_em (getHtmlString(getHeadIndexValue(i, dt, "content")))+"</p>"+
		"</section><footer><ul><li><span class=\"look\"></span><b>"+getHtmlString(getHeadIndexValue(i, dt, "nums"))+"</b></li><li><span class=\"reply\"></span><b>"+getHtmlString(getHeadIndexValue(i, dt, "discussNums"))+"</b></li>"
		var mId =  getHtmlString(getHeadIndexValue(i, dt, "memberId"))
		if(IsNotEmpty(mId)){
		htm+="<li id='li_"+  getHtmlString(getHeadIndexValue(i, dt, "id")) +"' onclick='parise("+getHtmlString(getHeadIndexValue(i, dt, "id"))+")'><span id='parise_"+getHtmlString(getHeadIndexValue(i, dt, "id"))+"' class=\"good wonderful\"></span><b>"+getHtmlString(getHeadIndexValue(i, dt, "praiseNums"))+"</b></li></ul></footer>";
		}else{
			htm+="<li id='li_"+getHtmlString(getHeadIndexValue(i, dt, "id")) +"' onclick='parise("+getHtmlString(getHeadIndexValue(i, dt, "id"))+")'><span id='parise_"+getHtmlString(getHeadIndexValue(i, dt, "id"))+"' class=\"good\"></span><b>"+getHtmlString(getHeadIndexValue(i, dt, "praiseNums"))+"</b></li></ul></footer>";
		}
		
		$("#info").append(htm)
	}
	

	
}

function getDiscuss(){
	 new qmsk.SiglePinterest({
			url : '../../../discuss/find/discussList', // 请求地址，插件会自动在 url 后追加 /n/n
			initPage : 3, // 首次加载页数
			size : 1, // 每次加载数量，即每页的大小
			success : printDataToPage, // 成功回调
			valves : 100 ,//当滚动条距离底部该像素的时候加载
			data:{'shopId':_shopId,'noteId':getIdByName("id")}
		});
}



function parise(id){
	if(IsEmpty(memberId)){
		alert("您还不是会员")
		return false;
	}
 	if(!$("#parise_"+id).hasClass("wonderful")){
 		var heads = new Array("noteId","memberId")
 		var datas = new Array(id,memberId)
 		var params= _getJsonParseInsertStr(heads, datas);
 		var dt = _insertInfoNoSucceedMessage("../../../notes/insert/insertParise", {'data':params})
 		if(IsNotEmpty(dt)&&dt.state==0){
 	 		var num= getHtmlInt($("#parise_"+id).next("b").html()) ;	
 	 		num++;
 	 		$("#parise_"+id).next("b").html(num)
 	 		$("#parise_"+id).addClass("wonderful");	
 		}
		}
		
		
	
}
function saveInfo(){
	var doflag=$("#doflag").val();
	if(doflag==1){
		addInfo()
	}else if(doflag==2){
		addReply()
	}
}

function addReply(){
	var content =$("#saytext").val();
	if(!checkNull(content, "内容", "content")){
		return false;
	}
	var parentId = $("#parentId").val();
	
	var discussId = $("#discussId").val()
	var toReplyId = $("#toReplyId").val()
	var name= null
	if(parentId==0){
		name= $("#plName_"+discussId).html()
	}else{
		name = $("#hfName_"+parentId).html()
	}
	var heads = new Array("content","replyUserId","replyUserName","discussId","discussName","parentId","discussUserId","openId")
	var datas = new Array(content,memberId,memberName,discussId,name,parentId,toReplyId,_openId)
	var params= _getJsonParseInsertStr(heads, datas);
	var dt=_insertInfoNoSucceedMessage("../../../discussReply/insert/insertInfo", {'data':params});
	if(dt.state==0){
		var id = getHtmlInt(getHeadIndexValue(0, dt, "id"))
		var htm="<article class='answer'> <dl><dt><img src=\""+imageUrl+"\"></dt><dd><strong>"+memberName+"</strong>回复<span class=\"det\">"+name+"</span><br><time>"+getHtmlString(getHeadIndexValue(0, dt, "createdTime"))+"</time></dd></dl><p>"+replace_em(content)+"</p><address class=\"talkThis\" onclick='toShowReply("+discussId+","+id+","+memberId+")' ></address></article>"
		$("#discuss_"+discussId).append(htm)
			restForm();
		toHidden()
	}else{
		alert("评论失败")
	}
	
	
}

function addInfo(){
	var content =$("#saytext").val();
	if(!checkNull(content, "内容", "content")){
		return false;
	}
	var noteId = getIdByName("id");
	if(IsEmpty(noteId)){
		alert("页面出错，请从微信页面进入")
		return false;
	}
	var heads = new Array("content","submitId","submitMan","noteId","openId","shopId")
	var datas = new Array(content,memberId,memberName,noteId,_openId,_shopId)
	var params= _getJsonParseInsertStr(heads, datas);
	var dt=_insertInfoNoSucceedMessage("../../../discuss/insert/insertInfo", {'data':params});
	if(dt.state==0){
		var id = getHtmlInt(getHeadIndexValue(0, dt, "id"))
		var htm=" <section id='discuss_"+id+"'  class=\"allDiscuss\"><article> <dl><dt><img src=\""+imageUrl+"\"></dt><dd><strong id='plName_"+id+"'>"+memberName+"</strong><br><time>"+getHtmlString(getHeadIndexValue(0, dt, "createdTime"))+"</time></dd></dl><p>"+replace_em(content)+"</p><address class=\"talkThis\" onclick='toShowReply("+id+",0,"+memberId+")' ></address></article></section>"
		$("#allDiscuss").prepend(htm);
		restForm();
		toHidden()
	}else{
		alert("评论失败")
	}
	
	
}

function restForm(){
	$("#title").val("");
	$("#saytext").val("");
	$("#memo").val("");
}


function printDataToPage(dt){
	for(var i = 0;i<dt.row;i++){
		var id= dt.getValue("id",i)
		var imageUrl= dt.getValue("imageUrl",i)
		if(IsEmpty(imageUrl)){
			imageUrl="../../images/userImg.jpg"
		}
		var content= dt.getValue("content",i)
		var createdTime= dt.getValue("createdTime",i)
		var name= dt.getValue("submitMan",i)
		var htm=" <section id='discuss_"+id+"'  class=\"allDiscuss\"><article> <dl><dt><img src=\""+imageUrl+"\"></dt><dd><strong id='plName_"+id+"'>"+name+"</strong><br><time>"+createdTime+"</time></dd></dl><p>"+replace_em(content)+"</p><address class=\"talkThis\" onclick='toShowReply("+id+",0,"+dt.getValue("submitId",i)+")' ></address></article>"		
		 var imagesList= _findInfo('../../../discussReply/find/allReply', {'id':id})
		if(IsNotEmpty(imagesList)&&imagesList.state==0&&imagesList.result.data.length>0){
			for(var j = 0 ; j<imagesList.result.data.length;j++){
				
			var imageUrl=getHtmlString(getHeadIndexValue(j, imagesList, "imageUrl"));
			if(IsEmpty(imageUrl)){
				imageUrl="../../images/userImg.jpg"
			}
			 htm+="<article class='answer' id='discuss_'> <dl><dt><img src=\""+imageUrl+"\"></dt><dd><strong id=\"hfName_"+getHtmlString(getHeadIndexValue(j, imagesList, "id"))+"\">"+getHtmlString(getHeadIndexValue(j, imagesList, "replyUserName"))+"</strong>回复<span class=\"det\">"+getHtmlString(getHeadIndexValue(j, imagesList, "discussName"))+"</span><br><time>"+getHtmlString(getHeadIndexValue(j, imagesList, "createdTime"))+"</time></dd></dl><p>"+replace_em(getHtmlString(getHeadIndexValue(j, imagesList, "content")))+"</p><address class=\"talkThis\" onclick='toShowReply("+id+","+getHtmlString(getHeadIndexValue(j, imagesList, "id"))+","+getHtmlString(getHeadIndexValue(j, imagesList, "id"))+")' ></address></article>"
			}
			
		} 
		htm+="</section>"
		
		$("#allDiscuss").append(htm)
	}
	

	
}

function toShowReply(discussId,parentId,toReplyId){
	$(".proDetails").animate({"top":0},function(){
		$("body").css("overflow-y","hidden");
	});
	$("#ti").html("评论")
	$("#doflag").val(2)
	$("#parentId").val(parentId)
	$("#discussId").val(discussId)
	$("#toReplyId").val(toReplyId)
}

function toPl(){
	$(".proDetails").animate({"top":0},function(){
		$("body").css("overflow-y","hidden");
	});
	$("#ti").html("评论")
	$("#doflag").val(1)

}

function goSy(){
	var htm = "?openId="+_openId+"&shopId="+getShopId();
	 redirectUrl('comeOver.html'+htm)
}
function goMine(){
	var htm = "?openId="+getOpenId()+"&shopId="+getShopId();
	redirectUrl('mineData.html'+htm)
}

</script>
<script type="text/javascript" src="../../js/jquery.qqFace.js"></script>
<script type="text/javascript">
$(function(){
	$('.emotion').qqFace({
		assign:'saytext', //给那个控件赋值
		path:'../../images/face/'	//表情存放的路径
	});
	$(".saytext").focus(function(){
		$(this).parent(".showFaceTxt").addClass("enterTxt");
	})
	$(".saytext").blur(function(){
		$(this).parent(".showFaceTxt").removeClass("enterTxt");
	})
});
//替换表情
</script>
</head>

<body>
<div class="proDetails">
 <div class="placeTit"><a class="back"></a>评论</div>
    <div class="det"> <div class="showFaceTxt">
      <textarea class="saytext" id="saytext"></textarea>
      <div class="com_form">
        <p><span class="emotion"></span> </p>
      </div>
    </div>
    <input type="hidden" id="doflag" value="1">
    <input type="hidden" id="parentId" value="0">
    <input type="hidden" id="discussId" value="0">
    <input type="hidden" id="toReplyId" value="0">

    </div>
    <div class="give">
        <input type="button" value="提交" class="giveBtn" onclick="saveInfo()">
    </div>
</div>
<div class="wrapper" style="padding-bottom:46px;">
  <div class="container" >
    <div class="comeGift "  id="info">
    <!--   <header>
        <dl>
          <dt><img src="../../images/userImg.jpg"></dt>
          <dd><strong>冰</strong><br>
            <time>2012-03-20 12:00</time>
          </dd>
        </dl>
        <aside><b></b><span>宝马</span><span class="red">3000</span>公里</aside>
      </header>
      <section>
      	<figure data-count="6张图片">
        	<div>
        	<img src="../../images/host1.jpg" data-src="http://img.weimob.com/67/05/d7/sns/20140313205136_49500.jpg" data-gid="g0" onload="preViewImg(this, event);">
        	<img src="../../images/host2.jpg" data-src="http://img.weimob.com/67/05/d7/sns/20140313205136_49500.jpg" data-gid="g0" onload="preViewImg(this, event);">
        	<img src="../../images/host3.jpg" data-src="http://img.weimob.com/67/05/d7/sns/20140313205136_49500.jpg" data-gid="g0" onload="preViewImg(this, event);">
        	<img src="../../images/host4.jpg" data-src="http://img.weimob.com/67/05/d7/sns/20140313205136_49500.jpg" data-gid="g0" onload="preViewImg(this, event);">
        	<img src="../../images/host5.jpg" data-src="http://img.weimob.com/67/05/d7/sns/20140313205136_49500.jpg" data-gid="g0" onload="preViewImg(this, event);">
        	<img src="../../images/host6.jpg" data-src="http://img.weimob.com/67/05/d7/sns/20140313205136_49500.jpg" data-gid="g0" onload="preViewImg(this, event);">
            </div>
        </figure>
        <h4 class="title">绵阳主播</h4>
        <p>价位哦IF奖陪我i减肥品味EFI金额为盲从口味快递费，建文件fine我veowsiv</p>
      <footer>
        <ul>
          <li><span class="look"></span><b>100</b></li>
          <li><span class="reply"></span><b>20</b></li>
          <li><span class="good"></span><b>10</b></li>
        </ul>
      </footer> -->
    </div>
    <!--over-->
    <div id="allDiscuss">
   <!--  <section class="allDiscuss">

    	<article >
            <dl>
              <dt><img src="../../images/userImg.jpg"></dt>
              <dd><strong>冰</strong>回复<span class="det">寒</span>：<br>
                <time>2012-03-20 12:00</time>
              </dd>
            </dl>
            <h4 class="title">绵阳主播</h4>
            <p>价位哦IF奖陪我i减肥品味EFI金额为盲从口味快递费金额为盲从口味快递费金额为盲从口味快递费，建文件fine我veowsiv</p>
            <address class="talkThis"></address>
        </article>
    </section>
    
     <section class="allDiscuss">
    	
    	<article>
            <dl>
              <dt><img src="../../images/userImg.jpg"></dt>
              <dd><strong>寒</strong><br>
                <time>2012-03-20 12:00</time>
              </dd>
            </dl>
            <p>价位哦IF奖陪我i减肥品味EFI金额为盲从口味快递费金额为盲从口味快递费金额为盲从口味快递费，建文件fine我veowsiv</p>
            <address class="talkThis"></address>
        </article>
    	<article class="answer">
            <dl>
              <dt><img src="../../images/userImg.jpg"></dt>
              <dd><strong>冰</strong>回复<span class="det">寒</span>：<br>
                <time>2012-03-20 12:00</time>
              </dd>
            </dl>
            <h4 class="title">绵阳主播</h4>
            <p>价位哦IF奖陪我i减肥品味EFI金额为盲从口味快递费金额为盲从口味快递费金额为盲从口味快递费，建文件fine我veowsiv</p>
            <address class="talkThis"></address>
        </article>
    </section> -->
    </div>
  </div>
  <footer class="giftBottom">
    <ul>
      <li onClick="goSy()"><span class="home"></span>首页</li>
      <li onclick="toPl()"><span class="giveTxt"  ></span>评论</li>
      <li onClick=" goMine()"><span class="mineHome"></span>我的</li>
    </ul>
  </footer>
</div>
</body>
</html>
